package com.ocean.web.controller.product;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ocean.common.annotation.Log;
import com.ocean.common.enums.BusinessType;
import com.ocean.productDict.domain.OForecastInterval;
import com.ocean.productDict.service.IOForecastIntervalService;
import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.utils.poi.ExcelUtil;
import com.ocean.common.core.page.TableDataInfo;

/**
 * 预报间隔维护Controller
 *
 * @author ocean
 * @date 2023-01-05
 */
@Controller
@RequestMapping("/product/forecastInterval")
public class OForecastIntervalController extends BaseController
{
    private String prefix = "product/forecastInterval";

    @Autowired
    private IOForecastIntervalService oForecastIntervalService;

    //@RequiresPermissions("product:forecastInterval:view")
    @GetMapping()
    public String forecastInterval()
    {
        return prefix + "/list";
    }

    /**
     * 查询预报间隔维护列表
     */
    //@RequiresPermissions("product:forecastInterval:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OForecastInterval oForecastInterval)
    {
        startPage();
        List<OForecastInterval> list = oForecastIntervalService.selectOForecastIntervalList(oForecastInterval);
        return getDataTable(list);
    }

    /**
     * 导出预报间隔维护列表
     */
    //@RequiresPermissions("product:forecastInterval:export")
    @Log(title = "预报间隔维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OForecastInterval oForecastInterval)
    {
        List<OForecastInterval> list = oForecastIntervalService.selectOForecastIntervalList(oForecastInterval);
        ExcelUtil<OForecastInterval> util = new ExcelUtil<OForecastInterval>(OForecastInterval.class);
        return util.exportExcel(list, "预报间隔维护数据");
    }

    /**
     * 新增预报间隔维护
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        Map<String,List> map = oForecastIntervalService.getNameAndCode();
        mmap.putAll(map);
        return prefix + "/add";
    }

    /**
     * 新增保存预报间隔维护
     */
    //@RequiresPermissions("product:forecastInterval:add")
    @Log(title = "预报间隔维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OForecastInterval oForecastInterval)
    {
        return toAjax(oForecastIntervalService.insertOForecastInterval(oForecastInterval));
    }

    /**
     * 修改预报间隔维护
     */
    //@RequiresPermissions("product:forecastInterval:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OForecastInterval oForecastInterval = oForecastIntervalService.selectOForecastIntervalById(id);
        mmap.put("oForecastInterval", oForecastInterval);
        Map<String,List> map = oForecastIntervalService.getNameAndCode();
        mmap.putAll(map);
        return prefix + "/edit";
    }

    /**
     * 修改保存预报间隔维护
     */
    //@RequiresPermissions("product:forecastInterval:edit")
    @Log(title = "预报间隔维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OForecastInterval oForecastInterval)
    {
        return toAjax(oForecastIntervalService.updateOForecastInterval(oForecastInterval));
    }

    /**
     * 删除预报间隔维护
     */
    //@RequiresPermissions("product:forecastInterval:remove")
    @Log(title = "预报间隔维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oForecastIntervalService.deleteOForecastIntervalByIds(ids));
    }

    /**
     * 修改预报间隔维护
     */
    //@RequiresPermissions("product:forecastInterval:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap)
    {
        OForecastInterval oForecastInterval = oForecastIntervalService.selectOForecastIntervalById(id);
        mmap.put("oForecastInterval", oForecastInterval);
        return prefix + "/detail";
    }
}
